package com.sebklebes.radar.radar;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

public class Preferences {

	private static final String TAG = Preferences.class.getName();
	private static final String SHARED_PREFS = "com.sebklebes.preferences";

	private static final String REAL_TIME_RADAR = "com.sebklebes.realtime";
	private static final String KNOWN_RADAR = "com.sebklebes.known";
	private static final String SPEEDCAMS = "com.sebklebes.speedcams";
	private static final String AUTOSTART = "com.sebklebes.autostart";

	private static SharedPreferences preferences;

	private static Preferences instance;

	private static boolean realTimeRadars;
	private static boolean knownRadars;
	private static boolean speedcams;
	private static boolean autostart;

	private Preferences(Context context) {
		preferences = context.getSharedPreferences(SHARED_PREFS,
				Context.MODE_PRIVATE);
		realTimeRadars = preferences.getBoolean(REAL_TIME_RADAR, false);
		knownRadars = preferences.getBoolean(KNOWN_RADAR, false);
		speedcams = preferences.getBoolean(SPEEDCAMS, false);
		autostart = preferences.getBoolean(AUTOSTART, false);
	}

	public static Preferences getInstance(Context context) {
		if (instance == null) {
			instance = new Preferences(context);
		}
		return instance;
	}

	public void saveRealTimeRadars(boolean realTime) {
		Preferences.realTimeRadars = realTime;
		SharedPreferences.Editor edit = preferences.edit();
		edit.putBoolean(REAL_TIME_RADAR, realTime);
		edit.commit();
		Log.d(TAG, "Saved [" + REAL_TIME_RADAR + "]  with value:  " + realTime);
	}

	public boolean isRealTimeRadars() {
		return realTimeRadars;
	}

	public void saveKnownRadars(boolean known) {
		Preferences.knownRadars = known;
		SharedPreferences.Editor edit = preferences.edit();
		edit.putBoolean(KNOWN_RADAR, known);
		edit.commit();
		Log.d(TAG, "Saved [" + KNOWN_RADAR + "]  with value:  " + known);
	}

	public boolean isKnownRadars() {
		return knownRadars;
	}

	public void saveSpeedCams(boolean speedCams) {
		Preferences.speedcams = speedCams;
		SharedPreferences.Editor edit = preferences.edit();
		edit.putBoolean(SPEEDCAMS, speedCams);
		edit.commit();
		Log.d(TAG, "Saved [" + SPEEDCAMS + "]  with value:  " + speedCams);
	}

	public boolean isSpeedCams() {
		return speedcams;
	}

	public void saveAutoStart(boolean autostart) {
		Preferences.autostart = autostart;
		SharedPreferences.Editor edit = preferences.edit();
		edit.putBoolean(AUTOSTART, autostart);
		edit.commit();
		Log.d(TAG, "Saved [" + AUTOSTART + "]  with value:  " + autostart);
	}

	public boolean isAutoStart() {
		return autostart;
	}
}
